import { setToken, getToken, removeToken } from '@/utils/storage'
import { getUserInfo } from '@/api/user'
export default {
  // state: { token: JSON.parse(localStorage.getItem('token')) || [] },
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    setToken(state, tokens) {
      state.token = tokens
      // localStorage.setItem('token', JSON.stringify(tokens))
      setToken(tokens)
    },
    removeToken(state) {
      state.token = {}
      // localStorage.removeItem('tokens')
      removeToken()
    },

    setUserInfo(state, data) {
      state.userInfo = data
    }
  },
  getters: {},
  actions: {
    async getUserInfo(context) {
      // 获取用户信息
      try {
        const res = await getUserInfo()
        context.commit('setUserInfo', res.data)
      } catch {
      }
    }
  },
  namespaced: true
}
